<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script type="text/javascript">
    //console.dir(Promise)
    function foo(){
        return new Promise((resolve,reject)=>{
            setTimeout(()=>{
                // resolve(123);
                reject({
                    err:'err',
                    code:101
                })
            },200)
        });
    }
    foo().then(data=>{
        console.log(data)  //接收resolve
    }).catch(data=>{
        console.log(data)  //接收reject
    }).finally(()=>{
        console.log('finished')
    })
    //写法2

    /*foo().then(data=>{
        console.log(data)  //接收resolve
    },data=>{
        console.log(data)  //接收reject
    }).finally(()=>{
        console.log('finished')
    })*/
    const promise1=new Promise((resolve,reject)=>{
        setTimeout(function(){
            reject('promise1')
        },1000)
    })
    const promise2=new Promise((resolve,reject)=>{
        setTimeout(function(){
            resolve('promise2')
        },2000)
    })
    Promise.race([promise1,promise2]).then(response=>{
        console.log(response)
        const [p1,p2]=response
    }).catch(err=>{
        Error(console.log("err:"+err))
    })

</script>
</body>
</html>